home *** CD-ROM | disk | FTP | other *** search
- #ifndef DOS_DOSEXTENS_H
- #include <dos/dosextens.h>
- #endif
-
- #ifndef WORKBENCH_STARTUP_H
- #include <workbench/startup.h>
- #endif
-
- #include <proto/exec.h>
- #include <proto/dos.h>
-
- #if defined(__SASC_510)
- void NewList(struct List *);
- #elif defined(__GNUC__)
- #include <proto/alib.h>
- #else
- #include <clib/alib_protos.h>
- #endif
-
- #include <stdlib.h>
- #include <stdio.h>
- #include <Amiga.h>
-
- #include "Internal.h"
-
- /************************************************************************/
-
- int AmigaMain(void); /* main program */
- void __exit(int) __NORETURN; /* "real" exit: restore stack and return */
- void _Startup(void) __NORETURN; /* C part of startup code; implemented below */
-
- /************************************************************************/
-
- struct ExecBase *SysBase;
- struct WBStartup *WorkbenchMessage;
- struct DosLibrary *DOSBase;
- struct Library *UtilityBase;
-
- struct MinList __stdioList;
-
- FILE __StdFiles[3];
-
- void (*MemoryCleanup)(void *);
-
- /************************************************************************/
-
- void _Startup(void)
-
- {
- struct Process *CurrentProcess;
-
- SysBase=*(struct ExecBase **)4;
- CurrentProcess=(struct Process *)FindTask(NULL);
-
- if (!CurrentProcess->pr_CLI)
- {
- do
- {
- WaitPort(&CurrentProcess->pr_MsgPort);
- }
- while (!(WorkbenchMessage=(struct WBStartup *)GetMsg(&CurrentProcess->pr_MsgPort)));
- }
-
- if ((DOSBase=(struct DosLibrary *)OpenLibrary("dos.library",37)))
- {
- if ((UtilityBase=OpenLibrary("utility.library",37)))
- {
- NewList((struct List *)&__stdioList);
- __StdFiles[0].Filehandle=Input();
- __StdFiles[1].Filehandle=Output();
- if (!(__StdFiles[2].Filehandle=CurrentProcess->pr_CES))
- {
- if (!(__StdFiles[2].Filehandle=Open("CONSOLE:",MODE_NEWFILE)))
- {
- __StdFiles[2].Filehandle=Output();
- }
- else
- {
- __StdFiles[2].Flags.Close=1;
- }
- }
- AddTail((struct List *)&__stdioList,(struct Node *)&__StdFiles[0].Node);
- AddTail((struct List *)&__stdioList,(struct Node *)&__StdFiles[1].Node);
- AddTail((struct List *)&__stdioList,(struct Node *)&__StdFiles[2].Node);
- exit(AmigaMain());
- }
- }
- exit(100);
- /* not reached */
- }
-
- /************************************************************************/
-
- void exit(int RC)
-
- {
- FILE *CurrentFile;
-
- for (CurrentFile=(FILE *)__stdioList.mlh_Head;
- CurrentFile->Node.mln_Succ;
- CurrentFile=(FILE *)CurrentFile->Node.mln_Succ)
- {
- if (CurrentFile->Flags.Close)
- {
- Close(CurrentFile->Filehandle);
- }
- }
-
- if (MemoryCleanup)
- {
- MemoryCleanup(__MemoryPool);
- }
-
- if (DOSBase)
- {
- CloseLibrary(&DOSBase->dl_lib);
- CloseLibrary(UtilityBase);
- }
-
- if (WorkbenchMessage)
- {
- ReplyMsg(&WorkbenchMessage->sm_Message);
- }
-
- __exit(RC);
- }
-